package com.ruoyi.web.controller.design;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.design.domain.ProductDict;
import com.ruoyi.design.domain.vo.ProductDictVo;
import com.ruoyi.design.service.IProductDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



@RestController
@RequestMapping("/product/dict")
public class ProductDictController extends BaseController {

    @Autowired
    IProductDictService dictService;

    /**
     * 查询字典数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProductDict productDict)
    {
        startPage();
        List<ProductDict> list = dictService.selectProductDictList(productDict);
        return getDataTable(list,null);
    }

    @PostMapping("/type")
    public AjaxResult dictDataByDictType(@RequestBody ProductDictVo productDictVo){
        List<String> list = productDictVo.getList();
        Integer parentId= productDictVo.getParentId();
//        System.out.println("list==="+list);
        Map<String,Object> map=new HashMap<>();
        map.put("dictList",list);
        map.put("parentId",parentId);
        List<ProductDict> productDicts = dictService.dictDataByDictType(map);
//        System.out.println("productDicts=="+productDicts);
        return AjaxResult.success(productDicts);
    }

    @PostMapping("/subtype")
    public AjaxResult subtypeDictDataByDictType(@RequestBody ProductDict dict){
        Long parentId = dictService.selectDictCodeByProductDict(dict);
//        List<ProductDict> dicts = dictService.dictDataByDictType(dict.getDictType(), parentId);
        return AjaxResult.success(null);
    }
}
